import { LoadingBar } from 'iview';
import { ObservablePromiseModel } from 'bggood-store-utils';
LoadingBar.config({
    color: '#5cb85c',
});
const LoadingPlugin={
    install:function(Vue,options){
        options=options||{};
        options.obStateType=options.obStateType||ObservablePromiseModel;
        Vue.prototype.loading=function(data){
            let isLoading = false;
            if (data) {
                if (data.isResolved) {
                    isLoading = false;
                } else if (data.isTimeout) {
                    isLoading = false;
                } else if (data.isServerError) {
                    isLoading = false;
                } else if (!data.isOnLine) {
                    isLoading = false;
                } else if (data.isRejected) {
                    isLoading = false;
                }
                else {
                    isLoading = true;
                }
            }
            else {
                isLoading = true;
            }
            return isLoading;
        }
        Vue.prototype.pageLoadingBar=function(state){
            if (state && state instanceof options.obStateType) {
                if (state.isPending && !state.isResolved) {
                    LoadingBar.start();
                }
                else if (state.isResolved) {
                    LoadingBar.finish();
                }
                else {
                    LoadingBar.error();
                }
            }
        }
    }
}
export default LoadingPlugin
